Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner/core: raise warning for unmatched join hint #9914

Merged
merged 5 commits into from
Apr 1, 2019

Conversation

alivxxx
Copy link
Contributor

@alivxxx alivxxx commented Mar 27, 2019

What problem does this PR solve?

When the join hint is incorrect, for example when it needs to use the table alias name while the table name in the hint is the original name, we can raise a warning to the client.

What is changed and how it works?

Add a new field to record whether the join hint is matched, and check it when we pop the table hints, if it is not matched, raise an warning.

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change

Side effects

  • None

Related changes

  • None

@alivxxx alivxxx added type/enhancement The issue or PR belongs to an enhancement. sig/planner SIG: Planner labels Mar 27, 2019
if curEntry.L == tableName.L {
joinHint.matched = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to mark hint as unmatched if any specified hint table cannot find a match? /cc @morgo

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value is false, is unmatched?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean if the hint contains t1 and t2, while the query only involves t2, should we raise warning?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If so, maybe it's more reasonable to raise a warning.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we define the matched as a string slice?
Thus we can print the accurate wrong table name in the warning message

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning sounds good to me. Note that in some cases, MySQL hints do not even raise warnings because they are considered hints (entirely optional to enforce vs. directives). I think we should just arrive at warnings and never errors.

if curEntry.L == tableName.L {
joinHint.matched = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value is false, is unmatched?

planner/core/planbuilder.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Mar 28, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@8a7c60d). Click here to learn what that means.
The diff coverage is 95.4545%.

@@            Coverage Diff             @@
##             master     #9914   +/-   ##
==========================================
  Coverage          ?   77.471%           
==========================================
  Files             ?       403           
  Lines             ?     81806           
  Branches          ?         0           
==========================================
  Hits              ?     63376           
  Misses            ?     13710           
  Partials          ?      4720

Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zimulala zimulala added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 28, 2019
Copy link
Contributor

@eurekaka eurekaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@eurekaka eurekaka added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Apr 1, 2019
@eurekaka
Copy link
Contributor

eurekaka commented Apr 1, 2019

/run-all-tests

@zz-jason
Copy link
Member

zz-jason commented Apr 1, 2019

/run-unit-test

@zz-jason zz-jason merged commit bab9e90 into pingcap:master Apr 1, 2019
@zz-jason
Copy link
Member

zz-jason commented Apr 1, 2019

@lamxTyler please cherry pick this PR to release-2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/planner SIG: Planner status/LGT2 Indicates that a PR has LGTM 2. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants